<template>
    <div class="wrap-food" @click.stop.prevent="clickAction">
        <img class="icon" :src="food.icon" alt>
        <span class="right-info">
            <div class="name nowrap">{{food.name}}</div>
            <div class="description nowrap">{{food.description}}</div>
            <div class="info">
                <span>月销售:{{food.sellCount}}</span>
                <span>好评率:{{food.rating}}</span>
            </div>
            <div class="price">
                <span class="now">¥{{food.price}}</span>
                <span v-show="food.oldPrice" class="old">¥{{food.oldPrice}}</span>
            </div>
        </span>
        <cart-control
            @minusAction="minusAction"
            @addAction="addAction"
            class="cart-count"
            :food="food"
        ></cart-control>
    </div>
</template>

<script>
import CartControl from './cartcontrol'
export default {
    props: {
        food: {
            type: Object
        }
    },
    components: {
        CartControl
    },
    methods: {
        minusAction() {
            if (this.food.count > 0) {
                this.food.count -= 1
            }
        },
        addAction() {
            if (!this.food.count) {
                this.$set(this.food, 'count', 1)
            } else {
                this.food.count += 1
            }
        },
        clickAction(event) {
            if (!event._constructed) {
                return
            }
            this.$emit('clickAction')
        }
    }
}
</script>

<style lang="less">
.wrap-food {
    display: flex;
    padding-bottom: 18px;
    .icon {
        width: 65px;
        height: 65px;
    }
    .right-info {
        display: flex;
        flex: 1;
        flex-direction: column;
        justify-content: space-between;
        font-size: 0;
        margin-left: 10px;
        overflow: hidden;
        .nowrap {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .name {
            display: inline-block;
            font-size: 15px;
            line-height: 15px;
            font-weight: bold;
            color: #333333;
        }
        .description {
            display: inline-block;
            font-size: 12px;
            line-height: 12px;
            color: #999999;
        }
        .info {
            display: inline-block;
            font-size: 12px;
            line-height: 12px;
            color: #999999;
            span {
                margin-right: 5px;
            }
        }
        .price {
            display: inline-block;
            span {
                margin-right: 5px;
            }
            .now {
                font-size: 15px;
                color: rgb(240, 20, 20);
            }
            .old {
                font-size: 13px;
                line-height: 13px;
                color: #999999;
                text-decoration: #999999 line-through;
            }
        }
    }
    .cart-count {
        position: absolute;
        bottom: 15px;
        right: 0;
    }
}
</style>
